import javax.swing.*;
import java.awt.*;
import java.util.logging.Logger;

class MyThread extends Thread
{
    Logger logger = MyLogger.getLogger();

    Frame frame;

    MyThread()
    {
        frame = new Frame();
    }

    public void run()
    {
        logger.info("MyThread.class.toString()");
        frame.Run();
    }
}

class Frame extends JFrame
{
    Graphics graphics;
    Logger logger = MyLogger.getLogger();
    private final int windowWidth;//画板的宽度
    private final int windowHeight;//画板的高度
    int backgroundY;
    Image image;
    private Image buffer;  // 双缓冲图像
    private Graphics bufferGraphics;  // 双缓冲图像的绘图上下文
    Frame()
    {
        setLayout(null);
        windowWidth = 629;
        windowHeight = 990;
        setSize(windowWidth, windowHeight);
        setLocationRelativeTo(null);
        setVisible(true);
        image = Toolkit.getDefaultToolkit().getImage( "D:\\Code\\JAVA\\Fighting\\resources\\images\\background_01.png");

        graphics = getContentPane().getGraphics();
        buffer = createImage(getWidth(), getHeight());
        bufferGraphics = buffer.getGraphics();
    }

    public void Run()
    {
        logger.info("");
        while (true)
        {
            //graphics.drawImage(image, 0, backgroundY, windowWidth, windowHeight, this);
            //graphics.drawImage()
            backgroundY += 10;
            bufferGraphics.drawImage(image, 0, backgroundY,null);
            bufferGraphics.setColor(new Color(100, 100,200));
            bufferGraphics.fillRect(100, 100, 200, 200);
            graphics.drawImage(buffer, 0, 0, null);

            /*
            -----------------------------------
©著作权归作者所有：来自51CTO博客作者mob64ca12f58d71的原创作品，请联系作者获取转载授权，否则将追究法律责任
                java双缓冲技术
            https://blog.51cto.com/u_16213453/6993214*/


            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class TestOnly {
    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        myThread.start();
    }
}
